import { http } from '../../http'
import { ResponsePage } from '@/service/api/type'
import {
  ActivityCouponDetailVo,
  CouponStatisticsVo,
  StoreAndCouponVo,
  StoreCategory,
  UserCouponDetailVo,
  UserCouponListVo,
  ValidCouponVo
} from '@/service/api/modules/coupon/response'
import { GetCouponsByCategoryParam, GetMyCouponListParam, ValidCouponParam } from '@/service/api/modules/coupon/param'

// 获取优惠券店铺分类
const getStoreCategories = () => http.get<void, StoreCategory[]>('/activity/coupon/store/categories')

// 获取优惠券
const getCouponsByCategory = (params: GetCouponsByCategoryParam) => http.get<GetCouponsByCategoryParam, ResponsePage<StoreAndCouponVo>>(`/activity/coupon/store/category/${params.categoryId}`, params)

// 获取优惠券详情
const getCouponDetail = (couponId: number | string) => http.get<number | string, ActivityCouponDetailVo>(`/activity/coupon/${couponId}`)

// 获取店铺的优惠券
const getCouponsByStore = (storeId: number | string) => http.get<GetCouponsByCategoryParam, StoreAndCouponVo[]>(`/activity/coupon/store/${storeId}/coupons`)

// 获取我的优惠券列表
const getMyCouponList = (params: GetMyCouponListParam) => http.get<GetMyCouponListParam, ResponsePage<UserCouponListVo>>('/activity/coupon/user', params)

// 获取优惠券、拼团的当前数量
const getMyCouponCount = () => http.get<void, CouponStatisticsVo>('/activity/coupon/statistics')

// 获取我的优惠券（已领取）的详情
const getMyCouponDetail = (userCouponId: number | string) => http.get<string, UserCouponDetailVo>(`/activity/coupon/user/detail/${userCouponId}`)

// 核销优惠券
const validateCoupon = (params: ValidCouponParam) => http.post<ValidCouponParam, ValidCouponVo>('/activity/coupon/valid', params)

// 获取优惠券状态
const getCouponStatus = (userCouponId: number | string) => http.get<string, number>(`/activity/coupon/user/${userCouponId}/status`)

export default {
  getStoreCategories,
  getCouponsByCategory,
  getCouponDetail,
  getCouponsByStore,
  getMyCouponList,
  getMyCouponCount,
  getMyCouponDetail,
  validateCoupon,
  getCouponStatus
}
